/*
 * @Author: 专送Pro
 * @Date: 2019-08-08 10:02:12
 * @LastEditors  : wuzhen
 * @LastEditTime : 2020-01-13 16:13:55
 * @Description: config配置
 */
const CompressionWebpackPlugin = require("compression-webpack-plugin");
const path = require("path");
const BASE_URL = process.env.NODE_ENV === "production" ? "/" : "/";
const resolve = dir => {
  return path.join(__dirname, dir);
};
// 服务器地址
const api = process.env.VUE_APP_BASEURL;
/**
 * @description: 区分打包环境与开发环境
 * process.env.NODE_ENV==='production'  (打包环境)
 * process.env.NODE_ENV==='development' (开发环境)
 * baseUrl: process.env.NODE_ENV==='production'?"":'/',
 * @return:
 */
module.exports = {
  publicPath: BASE_URL,
  outputDir: "dist",
  assetsDir: "static",
  indexPath: "index.html",
  runtimeCompiler: false,
  productionSourceMap: false,
  parallel: undefined,
  css: {
    // 配置css模块
    loaderOptions: {
      // 向预处理器 Loader 传递配置选项
      less: {
        // 配置less（其他样式解析用法一致）
        javascriptEnabled: true // 设置为true
      }
    }
  },
  chainWebpack: config => {
    // 指定入口  es6转es5
    config.entry.app = ["babel-polyfill", "./src/main.js"];
    config.resolve.alias.set("@", resolve("src")); // key,value自行定义，比如.set('@@', resolve('src/components'))
    config.resolve.alias.set("@images", resolve("./src/assets/images"));
  },
  devServer: {
    port: 8099,
    proxy: {
      "/pipes": {
        target: api, // 目标地址
        ws: true, // 是否代理websockets
        changeOrigin: true, // 设置同源  默认false，是否需要改变原始主机头为目标URL
        pathRewrite: {
          "^/pipes": "/pipes"
        }
      }
    }
  },
  configureWebpack: () => {
    if (process.env.NODE_ENV === "production") {
      return {
        plugins: [
          new CompressionWebpackPlugin({
            test: /\.js$|\.html|\.css|\.scss/,
            threshold: 10240,
            deleteOriginalAssets: false
          })
        ]
      };
    }
  },
  css: {
    modules: false
  }
};
